import axios from 'axios'


import {digElMessage} from "../common/Message.ts";

const request = axios.create({
    baseURL: '/app',
    timeout: 30000,
    withCredentials: true

})
request.interceptors.request.use(
    config => {
        let token = localStorage.getItem("token")
        if(token!=undefined||token!=null){
            config.headers["Authorization"]=token
        }
        return config
    },
    error => {

        digElMessage(error,"error",1000)


    }
)

request.interceptors.response.use(
    response => {

        if(response.data.code=='00000'){
            return response.data;
        }

        if(response.data.size){
            return  response
        }

        // else {
        //
        //     ElNotification({
        //         message: JSON.stringify(response),
        //         type: 'warning',
        //     })
        // }


    },
    error => {


        console.log(error)

        digElMessage(error.response.data.msg,"error",1000)





    }
)
export default request


